package com.kbbywyclient.presenter;

import android.content.Context;

import com.kbbywyclient.R;
import com.kbbywyclient.data.model.BankCardInfoModel;
import com.kbbywyclient.presenter.base.BasePresenter;
import com.kbbywyclient.service.ApiService;
import com.kbbywyclient.service.ApiServiceHelper;
import com.kbbywyclient.ui.contarct.CardHolderInfoContract;
import com.kbbywyclient.util.HttpExcUtil;
import com.kbbywyclient.util.RsaJsonUtil;

import javax.inject.Inject;

import rx.Subscriber;

/**
 * Created by Jiangzx on 2017/9/14 15:52.
 */

public class CardHolderInfoPresenter extends BasePresenter implements CardHolderInfoContract.Presenter {
    @Inject
    Context mContext;
    @Inject
    ApiService apiService;
    @Inject
    RsaJsonUtil jsonUtil;

    private CardHolderInfoContract.View view;

    @Inject
    public CardHolderInfoPresenter(CardHolderInfoContract.View view){
        this.view=view;
    }

    @Override
    public void getBankCardInfo(String cardNumber) {
        view.showLoadingDialog(mContext.getString(R.string.loading));
        jsonUtil.put("cardNo",cardNumber);

        ApiServiceHelper.
                appointThreadNormal(apiService.getBankCardInfo(jsonUtil.getRsaParams())).
                subscribe(new Subscriber<BankCardInfoModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        view.closeLoadingDialog();
                        HttpExcUtil.printError(e);
                    }

                    @Override
                    public void onNext(BankCardInfoModel model) {
                        view.closeLoadingDialog();
                        if(model.getData()!=null){
                            view.loadBankCardInfoSuccess(model.getData());
                        }
                    }
                });
    }
}
